Note: This tutorial assumes you are familiar with ROS topics and C++..
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

C++ Velocity for P2OS Robots

Description: This tutorial will go over the process by which one can control a P2OS robot with ROS and C++.

Keywords: p2os velocity geometry_msgs/Twist

Tutorial Level: BEGINNER

Velocity Command

To control the Velocity of the P2OS Robots, we will publish a geometry_msgs/Twist message on the topic /cmd_vel.

Here is some simple control code:

#include <ros/ros.h>
#include <ros/network.h>
#include <geometry_msgs/Twist.h>

/**
 * This tutorial demonstrates how to send a velocity command to a p2os robot
 */
const double TWIST_LINEAR = 0.5; //.5 m/s forward
const double TWIST_ANGULAR = 0; //0 rad/s 
int main(int argc, char **argv)
{
    ros::NodeHandle n;
    
    ros::Publisher cmd_pub = n.advertise<geometry_msgs::Twist>("/cmd_vel", 100);
    
    ros::Rate loop_rate(10);
    
    while (ros::ok())
    {
        geometry_msgs::Twist cmd_msg;
        cmd_msg.linear.x = TWIST_LINEAR;
        cmd_msg.angular.z = TWIST_ANGULAR;
        
        
        cmd_pub.publish(cmd_msg);
        
        ros::spinOnce();
        
        loop_rate.sleep();
    }
    
    
    return 0;
}

Run the above code, and the robot should move forward at a speed of 0.5 m/s.

Wiki: p2os-purdue/Tutorials/C++ Velocity Controller for P2OS Robots (last edited 2015-03-08 02:50:00 by HunterAllen)